package com.aaa.controller;

import com.aaa.entity.LayData;
import com.aaa.entity.LayTreeData;
import com.aaa.entity.TMenu;
import com.aaa.entity.User;
import com.aaa.service.TMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * (TMenu)表控制层
 *
 * @author yuyongli
 * @since 2022-10-24 09:37:03
 */
@Controller
@RequestMapping("tMenu")
public class TMenuController {
    /**
     * 服务对象
     */
    @Autowired
    private TMenuService tMenuService;

    // 查询所有的菜单 并且对应好他们之间的父子关系
    @GetMapping
    public String getAllMenu(HttpServletRequest request, HttpSession session){
        // 根据当前的登录的员工的信息  查询一下她对应的角色所拥有的菜单的信息

        // 如果角色的id 是1  就查询所有的菜单
        User user = (User) session.getAttribute("user");
        List<TMenu> menus = tMenuService.findAll(user.getRid());
        System.out.println(menus);
        request.setAttribute("menus",menus);
        return "main";
    }


    // 查询除tree所需要的数据   只要ajax LayData
    @GetMapping("treedata")
    @ResponseBody
    public LayData getAllMenu(){
       List<LayTreeData> treeDataList = tMenuService.getAllTreeMenu();
       return new LayData(treeDataList);
    }

    @GetMapping("checkData/{rid}")
    @ResponseBody
    public LayData checkData(@PathVariable Integer rid){
        List<Integer> checkDataList = tMenuService.getcheckDataList(rid);
        return new LayData(checkDataList);
    }



}

